<?php

namespace app\api\validate;

use think\Validate;
use app\common\model\UsersModel;

class RegisterValidate extends Validate
{
    protected $rule = [
        'username' => 'require|checkAccountUnique',
        'password' => 'require|min:6',
    ];

    protected $message = [
        'username.require' => '用户名不能为空',
        'username.checkAccountUnique' => '该用户名已被注册',
        'password.require' => '密码不能为空',
        'password.min' => '密码长度不能少于6位',
    ];

    // 检查账号是否唯一
    public function checkAccountUnique($value, $rule, $data = [])
    {
        return UsersModel::where('account', $value)->count() == 0;
    }
}
